<?php

class Myupload
{

    public $CI;
    public $base_url;

    public function __construct($myupload_config)
    {
        $this->CI = &get_instance();
        //通用设置
		$myupload_config['encrypt_name']=TRUE;
		$myupload_config['allowed_types']='gif|jpg|png';

		$this->CI->load->library('upload', $myupload_config);
    }

    /**
     * 上传文件
     *
     * @param $fileName
     * @return string
     */
    public function doUpload($fileName)
    {

        if ( ! $this->CI->upload->do_upload($fileName))
        {
            $error = array('error' => $this->CI->upload->display_errors());

            return array('code' => 0, 'data' => $error);
        }
        else
        {
            $data = array('upload_data' => $this->CI->upload->data());

            return array('code' => 1, 'data' => $data);
        }
    }
}
